// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package edu.uwlax.cs.oayonlinestore.entities;

import edu.uwlax.cs.oayonlinestore.vo.OrderItemVO;

public class OrderItemDaoImpl extends OrderItemDaoBase {

	/**
	 * Retrieves the entity object that is associated with the specified value
	 * object from the object store. If no such entity object exists in the
	 * object store, a new, blank entity is created
	 */
	private OrderItem loadOrderItemFromOrderItemVO(OrderItemVO orderItemVO) {
		OrderItem orderItem = this.load(orderItemVO.getId());
		if (orderItem == null) {
			orderItem = OrderItem.Factory.newInstance();
		}
		return orderItem;
	}

	public OrderItem orderItemVOToEntity(OrderItemVO orderItemVO) {
		OrderItem entity = this.loadOrderItemFromOrderItemVO(orderItemVO);
		this.orderItemVOToEntity(orderItemVO, entity, true);
		return entity;
	}

	public void toOrderItemVO(OrderItem source, OrderItemVO target) {
		super.toOrderItemVO(source, target);
		target.setProduct(getProductDao().toProductVO(source.getProduct()));
		target.setTotal(source.calcTotalPrice());
	}

}